using System;
using MySql.Data.MySqlClient;

namespace Scenario.Modules.DM.DataModel
{
	public class XMLDocumentFile : bOSdotNET.XML.Data.XMLObject, bOS.DataBase.bOSTable 
	{
		#region SQL Commands
		public const string SELECT = "select * from dm_document_files";
		#endregion

		public const string MAIN_NODE		= "File";

		private const string ID_ATTRIBUTE	= "Id";
		private const string TYPE_ATTRIBUTE	= "Type";
		private const string MIGRATE_POLICY_ATTRIBUTE = "MigratePolicy";
		private const string STATUS_ATTRIBUTE	= "Status";
		private const string NAME_ATTRIBUTE		= "Name";
		private const string DESCRIPTION_ATTRIBUTE		= "Description";


		private const string XML_TYPE		= "XML";
		private const string MSWORD_TYPE	= "MSWord";
		private const string MSEXCEL_TYPE	= "MSExcel";
		private const string PDF_TYPE		= "PDF";
		private const string INFOPATH_TYPE	= "InfoPath";

		public const string ALWAYS_MIGRATE_POLICY		= "ALWAYS";
		public const string DOCUMENT_MIGRATE_POLICY		= "DOCUMENT";
		public const string VERSION_MIGRATE_POLICY		= "VERSION";

		public const string LOCK_STATUS		= "LOCK";
		public const string UNLOCK_STATUS	= "UNLOCK";

		private string sName;
		private string sDescription;
		private string sStatus;
		private string sId;
		private string sType;
		private string sMigratePolicy;
		private string sDownload;

		public XMLDocumentFile()
		{
			this.Init();
		}

		public XMLDocumentFile(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		public string Id 
		{
			get { return sId; }
			set { sId = value; }
		}

		public string Type
		{
			get { return sType; }
			set { sType = value; }
		}

		public string MigratePolicy
		{
			get { return sMigratePolicy; }
			set { sMigratePolicy = value; }
		}

		public string Status
		{
			get { return sStatus; }
			set { sStatus = value; }
		}

		public string Name
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Description
		{
			get { return sDescription; }
			set { sDescription = value; }
		}

		public string Download
		{
			get { return sDownload;}
			set { sDownload = value;}
		}

		override public void Init()
		{
			sId = string.Empty;
			sType = string.Empty;
			sName=string.Empty;
			sDescription = string.Empty;
			sStatus = XMLDocumentFile.UNLOCK_STATUS;
			sMigratePolicy = XMLDocumentFile.ALWAYS_MIGRATE_POLICY;
		}

		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLDocumentFile.ID_ATTRIBUTE:
						sId = node.InnerText;
						break;

					case XMLDocumentFile.TYPE_ATTRIBUTE:
						sType = node.InnerText;
						break;

					case XMLDocumentFile.MIGRATE_POLICY_ATTRIBUTE:
						sMigratePolicy = node.InnerText;
						break;

					case XMLDocumentFile.STATUS_ATTRIBUTE:
						sStatus = node.InnerText;
						break;

					case XMLDocumentFile.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;

					case XMLDocumentFile.DESCRIPTION_ATTRIBUTE:
						sDescription = node.InnerText;
						break;

				}
			}
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLDocumentFile.MAIN_NODE);
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.ID_ATTRIBUTE ,sId));
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.TYPE_ATTRIBUTE,sType));
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.MIGRATE_POLICY_ATTRIBUTE,sMigratePolicy));
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.STATUS_ATTRIBUTE,sStatus));
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.NAME_ATTRIBUTE,sName));
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLDocumentFile.DESCRIPTION_ATTRIBUTE,sDescription));

			return xmlNode;
		}

		public void ReadFromDataBase(MySqlDataReader reader)
		{
			while (reader.Read() ) 
			{
				this.Id = reader.GetValue(0).ToString();
				this.Name=reader.GetValue(1).ToString();
				this.Description=reader.GetValue(2).ToString();
				this.Status=reader.GetValue(3).ToString();
				this.Type=reader.GetValue(4).ToString();
				this.MigratePolicy=reader.GetValue(5).ToString();
				this.Download=reader.GetValue(6).ToString();
			}
		}
	}
}
